﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
public partial class frmDiagnosisList : BaseLoginFrom
{
    public TextBox txtUserId = new TextBox();

    public frmDiagnosisList()
    {
        InitializeComponent();
        new TextBoxBindMonthCalendar(txtCreateDate);
        //Bind(false);
    }

    public frmDiagnosisList(string UserId, string UserName, string SerachBeginDate, string SearchEndDate)
        : this()
    {
        txtUserId.Text = UserId;
        txtUserName.Text = UserName;
        Bind();
    }

    private void btSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }

    private void Bind()
    {
        this.dgvUserList.AutoGenerateColumns = false;
        DataTable dt = null;

        dt = new Diagnosis().List(ApplictionData.CurrentUser.UserId, txtUserId.Text, txtUserName.Text, null, null);

        MemoryStream ms;


        ms = new MemoryStream();
        global::HealthExa.Properties.Resources.Edit.Save(ms, ImageFormat.Bmp);
        dt.Columns.Add(new DataColumn() { ColumnName = "Edit", DataType = typeof(byte[]), DefaultValue = ms.ToArray() });

        ms = new MemoryStream();
        global::HealthExa.Properties.Resources.Delete.Save(ms, ImageFormat.Bmp);
        dt.Columns.Add(new DataColumn() { ColumnName = "Delete", DataType = typeof(byte[]), DefaultValue = ms.ToArray() });

        ms = new MemoryStream();
        global::HealthExa.Properties.Resources.Child.Save(ms, ImageFormat.Bmp);
        dt.Columns.Add(new DataColumn() { ColumnName = "Child", DataType = typeof(byte[]), DefaultValue = ms.ToArray() });
        this.dgvUserList.DataSource = dt;
    }

    private void dgvUserList_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridView dgv = sender as DataGridView;
        DataRow dr = ((DataTable)(dgv.DataSource)).Rows[e.RowIndex];
        BaseWinFrom bwf = this.TopLevelControl as BaseWinFrom;
        switch (e.ColumnIndex)
        {
            case 5:
                bwf.AddMdiChildren(new frmDiagnosis(dr["Id"].ToString()));
                break;
            case 7:
                bwf.AddMdiChildren(new frmDiagnosis(new Diagnosis() { Patient = new UserExtense { UserId = dr["PatientId"].ToString() } }));
                break;
        }
    }

    private void txtCreateDate_Enter(object sender, EventArgs e)
    {

    }

    private void mcd_DateSelected(object sender, DateRangeEventArgs e)
    {
        txtCreateDate.Text = e.Start.ToString("yyyy-MM-dd 00:00:00");
        ((Control)sender).Visible = false;
    }

    private void mcd_MouseLeave(object sender, EventArgs e)
    {
        txtCreateDate.Text = string.Empty;
        ((Control)sender).Visible = false;
    }
}